Less obtrusive RC patrol feature, also works with enhanced RC, disable client side...
[lhc/web/wiklou.git] / includes / Skin.php
1 <?php
2
3 /**
4 *
5 * @package MediaWiki
6 * @subpackage Skins
7 */
8
9 /**
10 * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
11 */
12 if( defined( "MEDIAWIKI" ) ) {
13
14 # See skin.doc
15 require_once( 'Image.php' );
16
17 # These are the INTERNAL names, which get mapped directly to class names and
18 # file names in ./skins/. For display purposes, the Language class has
19 # internationalized names
20 #
21 /*
22 $wgValidSkinNames = array(
23 'standard' => 'Standard',
24 'nostalgia' => 'Nostalgia',
25 'cologneblue' => 'CologneBlue'
26 );
27 if( $wgUsePHPTal ) {
28 #$wgValidSkinNames[] = 'PHPTal';
29 #$wgValidSkinNames['davinci'] = 'DaVinci';
30 #$wgValidSkinNames['mono'] = 'Mono';
31 #$wgValidSkinNames['monobookminimal'] = 'MonoBookMinimal';
32 $wgValidSkinNames['monobook'] = 'MonoBook';
33 $wgValidSkinNames['myskin'] = 'MySkin';
34 $wgValidSkinNames['chick'] = 'Chick';
35 }
36 */
37
38 # Get a list of all skins available in /skins/
39 # Build using the regular expression '^(.*).php$'
40 # Array keys are all lower case, array value keep the case used by filename
41 #
42
43 $skinDir = dir($IP.'/skins');
44
45 # while code from www.php.net
46 while (false !== ($file = $skinDir->read())) {
47 if(preg_match('/^(.*).php$/',$file, $matches)) {
48 $aSkin = $matches[1];
49 $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
50 }
51 }
52 $skinDir->close();
53 unset($matches);
54
55 require_once( 'RecentChange.php' );
56
57 global $wgLinkHolders;
58 $wgLinkHolders = array(
59 'namespaces' => array(),
60 'dbkeys' => array(),
61 'queries' => array(),
62 'texts' => array(),
63 'titles' => array()
64 );
65 global $wgInterwikiLinkHolders;
66 $wgInterwikiLinkHolders = array();
67
68 /**
69 * @todo document
70 * @package MediaWiki
71 */
72 class RCCacheEntry extends RecentChange
73 {
74 var $secureName, $link;
75 var $curlink , $difflink, $lastlink , $usertalklink , $versionlink ;
76 var $userlink, $timestamp, $watched;
77
78 function newFromParent( $rc )
79 {
80 $rc2 = new RCCacheEntry;
81 $rc2->mAttribs = $rc->mAttribs;
82 $rc2->mExtra = $rc->mExtra;
83 return $rc2;
84 }
85 } ;
86
87
88 /**
89 * The main skin class that provide methods and properties for all other skins
90 * including PHPTal skins.
91 * This base class is also the "Standard" skin.
92 * @package MediaWiki
93 */
94 class Skin {
95 /**#@+
96 * @access private
97 */
98 var $lastdate, $lastline;
99 var $linktrail ; # linktrail regexp
100 var $rc_cache ; # Cache for Enhanced Recent Changes
101 var $rcCacheIndex ; # Recent Changes Cache Counter for visibility toggle
102 var $rcMoveIndex;
103 var $postParseLinkColour = false;
104 /**#@-*/
105
106 function Skin() {
107 $this->linktrail = wfMsg('linktrail');
108 }
109
110 function getSkinNames() {
111 global $wgValidSkinNames;
112 return $wgValidSkinNames;
113 }
114
115 function getStylesheet() {
116 return 'common/wikistandard.css';
117 }
118
119 function getSkinName() {
120 return 'standard';
121 }
122
123 /**
124 * Get/set accessor for delayed link colouring
125 */
126 function postParseLinkColour( $setting = NULL ) {
127 return wfSetVar( $this->postParseLinkColour, $setting );
128 }
129
130 function qbSetting() {
131 global $wgOut, $wgUser;
132
133 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
134 $q = $wgUser->getOption( 'quickbar' );
135 if ( '' == $q ) { $q = 0; }
136 return $q;
137 }
138
139 function initPage( &$out ) {
140 $fname = 'Skin::initPage';
141 wfProfileIn( $fname );
142
143 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => '/favicon.ico' ) );
144
145 $this->addMetadataLinks($out);
146
147 wfProfileOut( $fname );
148 }
149
150 function addMetadataLinks( &$out ) {
151 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf, $wgRdfMimeType, $action;
152 global $wgRightsPage, $wgRightsUrl;
153
154 if( $out->isArticleRelated() ) {
155 # note: buggy CC software only reads first "meta" link
156 if( $wgEnableCreativeCommonsRdf ) {
157 $out->addMetadataLink( array(
158 'title' => 'Creative Commons',
159 'type' => 'application/rdf+xml',
160 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
161 }
162 if( $wgEnableDublinCoreRdf ) {
163 $out->addMetadataLink( array(
164 'title' => 'Dublin Core',
165 'type' => 'application/rdf+xml',
166 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
167 }
168 }
169 $copyright = '';
170 if( $wgRightsPage ) {
171 $copy = Title::newFromText( $wgRightsPage );
172 if( $copy ) {
173 $copyright = $copy->getLocalURL();
174 }
175 }
176 if( !$copyright && $wgRightsUrl ) {
177 $copyright = $wgRightsUrl;
178 }
179 if( $copyright ) {
180 $out->addLink( array(
181 'rel' => 'copyright',
182 'href' => $copyright ) );
183 }
184 }
185
186 function outputPage( &$out ) {
187 global $wgDebugComments;
188
189 wfProfileIn( 'Skin::outputPage' );
190 $this->initPage( $out );
191 $out->out( $out->headElement() );
192
193 $out->out( "\n<body" );
194 $ops = $this->getBodyOptions();
195 foreach ( $ops as $name => $val ) {
196 $out->out( " $name='$val'" );
197 }
198 $out->out( ">\n" );
199 if ( $wgDebugComments ) {
200 $out->out( "<!-- Wiki debugging output:\n" .
201 $out->mDebugtext . "-->\n" );
202 }
203 $out->out( $this->beforeContent() );
204
205 $out->out( $out->mBodytext . "\n" );
206
207 $out->out( $this->afterContent() );
208
209 wfProfileClose();
210 $out->out( $out->reportTime() );
211
212 $out->out( "\n</body></html>" );
213 }
214
215 function getHeadScripts() {
216 global $wgStylePath, $wgUser, $wgContLang, $wgAllowUserJs;
217 $r = "<script type=\"text/javascript\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
218 if( $wgAllowUserJs && $wgUser->getID() != 0 ) { # logged in
219 $userpage = $wgContLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
220 $userjs = htmlspecialchars($this->makeUrl($userpage.'/'.$this->getSkinName().'.js', 'action=raw&ctype=text/javascript'));
221 $r .= '<script type="text/javascript" src="'.$userjs."\"></script>\n";
222 }
223 return $r;
224 }
225
226 # get the user/site-specific stylesheet, SkinPHPTal called from RawPage.php (settings are cached that way)
227 function getUserStylesheet() {
228 global $wgOut, $wgStylePath, $wgContLang, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
229 $sheet = $this->getStylesheet();
230 $action = $wgRequest->getText('action');
231 $s = "@import \"$wgStylePath/$sheet\";\n";
232 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css\";\n";
233 if( $wgAllowUserCss && $wgUser->getID() != 0 ) { # logged in
234 if($wgTitle->isCssSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
235 $s .= $wgRequest->getText('wpTextbox1');
236 } else {
237 $userpage = $wgContLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
238 $s.= '@import "'.$this->makeUrl($userpage.'/'.$this->getSkinName().'.css', 'action=raw&ctype=text/css').'";'."\n";
239 }
240 }
241 $s .= $this->doGetUserStyles();
242 return $s."\n";
243 }
244
245 /**
246 * placeholder, returns generated js in monobook
247 */
248 function getUserJs() { return; }
249
250 /**
251 * Return html code that include User stylesheets
252 */
253 function getUserStyles() {
254 global $wgOut, $wgStylePath, $wgLang;
255 $s = "<style type='text/css'>\n";
256 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
257 $s .= $this->getUserStylesheet();
258 $s .= "/*]]>*/ /* */\n";
259 $s .= "</style>\n";
260 return $s;
261 }
262
263 /**
264 * Some styles that are set by user through the user settings interface.
265 */
266 function doGetUserStyles() {
267 global $wgUser, $wgContLang;
268
269 $csspage = $wgContLang->getNsText( NS_MEDIAWIKI ) . ':' . $this->getSkinName() . '.css';
270 $s = '@import "'.$this->makeUrl($csspage, 'action=raw&ctype=text/css')."\";\n";
271
272 if ( 1 == $wgUser->getOption( 'underline' ) ) {
273 # Don't override browser settings
274 } else {
275 # CHECK MERGE @@@
276 # Force no underline
277 $s .= "a { text-decoration: none; }\n";
278 }
279 if ( 1 == $wgUser->getOption( 'highlightbroken' ) ) {
280 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
281 }
282 if ( 1 == $wgUser->getOption( 'justify' ) ) {
283 $s .= "#article { text-align: justify; }\n";
284 }
285 return $s;
286 }
287
288 function getBodyOptions() {
289 global $wgUser, $wgTitle, $wgNamespaceBackgrounds, $wgOut, $wgRequest;
290
291 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
292
293 if ( 0 != $wgTitle->getNamespace() ) {
294 $a = array( 'bgcolor' => '#ffffec' );
295 }
296 else $a = array( 'bgcolor' => '#FFFFFF' );
297 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
298 (!$wgTitle->isProtected() || $wgUser->isAllowed('protect')) ) {
299 $t = wfMsg( 'editthispage' );
300 $oid = $red = '';
301 if ( !empty($redirect) && $redirect == 'no' ) {
302 $red = "&redirect={$redirect}";
303 }
304 if ( !empty($oldid) && ! isset( $diff ) ) {
305 $oid = "&oldid=" . IntVal( $oldid );
306 }
307 $s = $wgTitle->getFullURL( "action=edit{$oid}{$red}" );
308 $s = 'document.location = "' .$s .'";';
309 $a += array ('ondblclick' => $s);
310
311 }
312 $a['onload'] = $wgOut->getOnloadHandler();
313 return $a;
314 }
315
316 function getExternalLinkAttributes( $link, $text, $class='' ) {
317 global $wgUser, $wgOut, $wgContLang;
318
319 $same = ($link == $text);
320 $link = urldecode( $link );
321 $link = $wgContLang->checkTitleEncoding( $link );
322 $link = str_replace( '_', ' ', $link );
323 $link = htmlspecialchars( $link );
324
325 $r = ($class != '') ? " class='$class'" : " class='external'";
326
327 if ( !$same && $wgUser->getOption( 'hover' ) ) {
328 $r .= " title=\"{$link}\"";
329 }
330 return $r;
331 }
332
333 function getInternalLinkAttributes( $link, $text, $broken = false ) {
334 global $wgUser, $wgOut;
335
336 $link = urldecode( $link );
337 $link = str_replace( '_', ' ', $link );
338 $link = htmlspecialchars( $link );
339
340 if ( $broken == 'stub' ) {
341 $r = ' class="stub"';
342 } else if ( $broken == 'yes' ) {
343 $r = ' class="new"';
344 } else {
345 $r = '';
346 }
347
348 if ( 1 == $wgUser->getOption( 'hover' ) ) {
349 $r .= " title=\"{$link}\"";
350 }
351 return $r;
352 }
353
354 /**
355 * @param bool $broken
356 */
357 function getInternalLinkAttributesObj( &$nt, $text, $broken = false ) {
358 global $wgUser, $wgOut;
359
360 if ( $broken == 'stub' ) {
361 $r = ' class="stub"';
362 } else if ( $broken == 'yes' ) {
363 $r = ' class="new"';
364 } else {
365 $r = '';
366 }
367
368 if ( 1 == $wgUser->getOption( 'hover' ) ) {
369 $r .= ' title="' . $nt->getEscapedText() . '"';
370 }
371 return $r;
372 }
373
374 /**
375 * URL to the logo
376 */
377 function getLogo() {
378 global $wgLogo;
379 return $wgLogo;
380 }
381
382 /**
383 * This will be called immediately after the <body> tag. Split into
384 * two functions to make it easier to subclass.
385 */
386 function beforeContent() {
387 global $wgUser, $wgOut;
388
389 return $this->doBeforeContent();
390 }
391
392 function doBeforeContent() {
393 global $wgUser, $wgOut, $wgTitle, $wgContLang, $wgSiteNotice;
394 $fname = 'Skin::doBeforeContent';
395 wfProfileIn( $fname );
396
397 $s = '';
398 $qb = $this->qbSetting();
399
400 if( $langlinks = $this->otherLanguages() ) {
401 $rows = 2;
402 $borderhack = '';
403 } else {
404 $rows = 1;
405 $langlinks = false;
406 $borderhack = 'class="top"';
407 }
408
409 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
410 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
411
412 $shove = ($qb != 0);
413 $left = ($qb == 1 || $qb == 3);
414 if($wgContLang->isRTL()) $left = !$left;
415
416 if ( !$shove ) {
417 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
418 $this->logoText() . '</td>';
419 } elseif( $left ) {
420 $s .= $this->getQuickbarCompensator( $rows );
421 }
422 $l = $wgContLang->isRTL() ? 'right' : 'left';
423 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
424
425 $s .= $this->topLinks() ;
426 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
427
428 $r = $wgContLang->isRTL() ? "left" : "right";
429 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
430 $s .= $this->nameAndLogin();
431 $s .= "\n<br />" . $this->searchForm() . "</td>";
432
433 if ( $langlinks ) {
434 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
435 }
436
437 if ( $shove && !$left ) { # Right
438 $s .= $this->getQuickbarCompensator( $rows );
439 }
440 $s .= "</tr>\n</table>\n</div>\n";
441 $s .= "\n<div id='article'>\n";
442
443 if( $wgSiteNotice ) {
444 $s .= "\n<div id='siteNotice'>$wgSiteNotice</div>\n";
445 }
446 $s .= $this->pageTitle();
447 $s .= $this->pageSubtitle() ;
448 $s .= $this->getCategories();
449 wfProfileOut( $fname );
450 return $s;
451 }
452
453
454 function getCategoryLinks () {
455 global $wgOut, $wgTitle, $wgUser, $wgParser;
456 global $wgUseCategoryMagic, $wgUseCategoryBrowser, $wgLang;
457
458 if( !$wgUseCategoryMagic ) return '' ;
459 if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
460
461 # Taken out so that they will be displayed in previews -- TS
462 #if( !$wgOut->isArticle() ) return '';
463
464 $t = implode ( ' | ' , $wgOut->mCategoryLinks ) ;
465 $s = $this->makeKnownLink( 'Special:Categories',
466 wfMsg( 'categories' ), 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
467 . ': ' . $t;
468
469 # optional 'dmoz-like' category browser. Will be shown under the list
470 # of categories an article belong to
471 if($wgUseCategoryBrowser) {
472 $s .= '<br/><hr/>';
473
474 # get a big array of the parents tree
475 $parenttree = $wgTitle->getCategorieBrowser();
476
477 # Render the array as a serie of links
478 function walkThrough ($tree) {
479 global $wgUser;
480 $sk = $wgUser->getSkin();
481 $return = '';
482 foreach($tree as $element => $parent) {
483 if(empty($parent)) {
484 # element start a new list
485 $return .= '<br />';
486 } else {
487 # grab the others elements
488 $return .= walkThrough($parent);
489 }
490 # add our current element to the list
491 $eltitle = Title::NewFromText($element);
492 # FIXME : should be makeLink() [AV]
493 $return .= $sk->makeKnownLink($element, $eltitle->getText()).' &gt; ';
494 }
495 return $return;
496 }
497
498 $s .= walkThrough($parenttree);
499 }
500
501 return $s;
502 }
503
504 function getCategories() {
505 $catlinks=$this->getCategoryLinks();
506 if(!empty($catlinks)) {
507 return "<p class='catlinks'>{$catlinks}</p>";
508 }
509 }
510
511 function getQuickbarCompensator( $rows = 1 ) {
512 return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
513 }
514
515 # This gets called immediately before the </body> tag.
516 #
517 function afterContent() {
518 global $wgUser, $wgOut, $wgServer;
519 global $wgTitle, $wgLang;
520
521 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
522 return $printfooter . $this->doAfterContent();
523 }
524
525 function printSource() {
526 global $wgTitle;
527 $url = htmlspecialchars( $wgTitle->getFullURL() );
528 return wfMsg( "retrievedfrom", "<a href=\"$url\">$url</a>" );
529 }
530
531 function printFooter() {
532 return "<p>" . $this->printSource() .
533 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
534 }
535
536 function doAfterContent() {
537 # overloaded by derived classes
538 }
539
540 function pageTitleLinks() {
541 global $wgOut, $wgTitle, $wgUser, $wgContLang, $wgUseApproval, $wgRequest;
542
543 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
544 $action = $wgRequest->getText( 'action' );
545
546 $s = $this->printableLink();
547 $disclaimer = $this->disclaimerLink(); # may be empty
548 if( $disclaimer ) {
549 $s .= ' | ' . $disclaimer;
550 }
551
552 if ( $wgOut->isArticleRelated() ) {
553 if ( $wgTitle->getNamespace() == Namespace::getImage() ) {
554 $name = $wgTitle->getDBkey();
555 $link = htmlspecialchars( Image::wfImageUrl( $name ) );
556 $style = $this->getInternalLinkAttributes( $link, $name );
557 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
558 }
559 # This will show the "Approve" link if $wgUseApproval=true;
560 if ( isset ( $wgUseApproval ) && $wgUseApproval )
561 {
562 $t = $wgTitle->getDBkey();
563 $name = 'Approve this article' ;
564 $link = "http://test.wikipedia.org/w/magnus/wiki.phtml?title={$t}&action=submit&doit=1" ;
565 #htmlspecialchars( wfImageUrl( $name ) );
566 $style = $this->getExternalLinkAttributes( $link, $name );
567 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>" ;
568 }
569 }
570 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
571 $s .= ' | ' . $this->makeKnownLink( $wgTitle->getPrefixedText(),
572 wfMsg( 'currentrev' ) );
573 }
574
575 if ( $wgUser->getNewtalk() ) {
576 # do not show "You have new messages" text when we are viewing our
577 # own talk page
578
579 if(!(strcmp($wgTitle->getText(),$wgUser->getName()) == 0 &&
580 $wgTitle->getNamespace()==Namespace::getTalk(Namespace::getUser()))) {
581 $n =$wgUser->getName();
582 $tl = $this->makeKnownLink( $wgContLang->getNsText(
583 Namespace::getTalk( Namespace::getUser() ) ) . ":{$n}",
584 wfMsg('newmessageslink') );
585 $s.= ' | <strong>'. wfMsg( 'newmessages', $tl ) . '</strong>';
586 # disable caching
587 $wgOut->setSquidMaxage(0);
588 $wgOut->enableClientCache(false);
589 }
590 }
591
592 $undelete = $this->getUndeleteLink();
593 if( !empty( $undelete ) ) {
594 $s .= ' | '.$undelete;
595 }
596 return $s;
597 }
598
599 function getUndeleteLink() {
600 global $wgUser, $wgTitle, $wgContLang, $action;
601 if( $wgUser->isAllowed('rollback') &&
602 (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
603 ($n = $wgTitle->isDeleted() ) ) {
604 return wfMsg( 'thisisdeleted',
605 $this->makeKnownLink(
606 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
607 wfMsg( 'restorelink', $n ) ) );
608 }
609 return '';
610 }
611
612 function printableLink() {
613 global $wgOut, $wgFeedClasses, $wgRequest;
614
615 $baseurl = $_SERVER['REQUEST_URI'];
616 if( strpos( '?', $baseurl ) == false ) {
617 $baseurl .= '?';
618 } else {
619 $baseurl .= '&';
620 }
621 $baseurl = htmlspecialchars( $baseurl );
622 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
623
624 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
625 if( $wgOut->isSyndicated() ) {
626 foreach( $wgFeedClasses as $format => $class ) {
627 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
628 $s .= " | <a href=\"$feedurl\">{$format}</a>";
629 }
630 }
631 return $s;
632 }
633
634 function pageTitle() {
635 global $wgOut, $wgTitle, $wgUser;
636
637 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
638 if($wgUser->getOption( 'editsectiononrightclick' ) && $wgTitle->userCanEdit()) { $s=$this->editSectionScript($wgTitle, 0,$s);}
639 return $s;
640 }
641
642 function pageSubtitle() {
643 global $wgOut;
644
645 $sub = $wgOut->getSubtitle();
646 if ( '' == $sub ) {
647 global $wgExtraSubtitle;
648 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
649 }
650 $subpages = $this->subPageSubtitle();
651 $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
652 $s = "<p class='subtitle'>{$sub}</p>\n";
653 return $s;
654 }
655
656 function subPageSubtitle() {
657 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
658 $subpages = '';
659 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
660 $ptext=$wgTitle->getPrefixedText();
661 if(preg_match('/\//',$ptext)) {
662 $links = explode('/',$ptext);
663 $c = 0;
664 $growinglink = '';
665 foreach($links as $link) {
666 $c++;
667 if ($c<count($links)) {
668 $growinglink .= $link;
669 $getlink = $this->makeLink( $growinglink, $link );
670 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
671 if ($c>1) {
672 $subpages .= ' | ';
673 } else {
674 $subpages .= '&lt; ';
675 }
676 $subpages .= $getlink;
677 $growinglink .= '/';
678 }
679 }
680 }
681 }
682 return $subpages;
683 }
684
685 function nameAndLogin() {
686 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader, $wgIP;
687
688 $li = $wgContLang->specialPage( 'Userlogin' );
689 $lo = $wgContLang->specialPage( 'Userlogout' );
690
691 $s = '';
692 if ( 0 == $wgUser->getID() ) {
693 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
694 $n = $wgIP;
695
696 $tl = $this->makeKnownLink( $wgContLang->getNsText(
697 Namespace::getTalk( Namespace::getUser() ) ) . ":{$n}",
698 $wgContLang->getNsText( Namespace::getTalk( 0 ) ) );
699
700 $s .= $n . ' ('.$tl.')';
701 } else {
702 $s .= wfMsg('notloggedin');
703 }
704
705 $rt = $wgTitle->getPrefixedURL();
706 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
707 $q = '';
708 } else { $q = "returnto={$rt}"; }
709
710 $s .= "\n<br />" . $this->makeKnownLink( $li,
711 wfMsg( 'login' ), $q );
712 } else {
713 $n = $wgUser->getName();
714 $rt = $wgTitle->getPrefixedURL();
715 $tl = $this->makeKnownLink( $wgContLang->getNsText(
716 Namespace::getTalk( Namespace::getUser() ) ) . ":{$n}",
717 $wgContLang->getNsText( Namespace::getTalk( 0 ) ) );
718
719 $tl = " ({$tl})";
720
721 $s .= $this->makeKnownLink( $wgContLang->getNsText(
722 Namespace::getUser() ) . ":{$n}", $n ) . "{$tl}<br />" .
723 $this->makeKnownLink( $lo, wfMsg( 'logout' ),
724 "returnto={$rt}" ) . ' | ' .
725 $this->specialLink( 'preferences' );
726 }
727 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
728 wfMsg( 'help' ) );
729
730 return $s;
731 }
732
733 function getSearchLink() {
734 $searchPage =& Title::makeTitle( NS_SPECIAL, 'Search' );
735 return $searchPage->getLocalURL();
736 }
737
738 function escapeSearchLink() {
739 return htmlspecialchars( $this->getSearchLink() );
740 }
741
742 function searchForm() {
743 global $wgRequest;
744 $search = $wgRequest->getText( 'search' );
745
746 $s = '<form name="search" class="inline" method="post" action="'
747 . $this->escapeSearchLink() . "\">\n"
748 . '<input type="text" name="search" size="19" value="'
749 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
750 . '<input type="submit" name="go" value="' . wfMsg ('go') . '" />&nbsp;'
751 . '<input type="submit" name="fulltext" value="' . wfMsg ('search') . "\" />\n</form>";
752
753 return $s;
754 }
755
756 function topLinks() {
757 global $wgOut;
758 $sep = " |\n";
759
760 $s = $this->mainPageLink() . $sep
761 . $this->specialLink( 'recentchanges' );
762
763 if ( $wgOut->isArticleRelated() ) {
764 $s .= $sep . $this->editThisPage()
765 . $sep . $this->historyLink();
766 }
767 # Many people don't like this dropdown box
768 #$s .= $sep . $this->specialPagesList();
769
770 return $s;
771 }
772
773 function bottomLinks() {
774 global $wgOut, $wgUser, $wgTitle;
775 $sep = " |\n";
776
777 $s = '';
778 if ( $wgOut->isArticleRelated() ) {
779 $s .= '<strong>' . $this->editThisPage() . '</strong>';
780 if ( 0 != $wgUser->getID() ) {
781 $s .= $sep . $this->watchThisPage();
782 }
783 $s .= $sep . $this->talkLink()
784 . $sep . $this->historyLink()
785 . $sep . $this->whatLinksHere()
786 . $sep . $this->watchPageLinksLink();
787
788 if ( $wgTitle->getNamespace() == Namespace::getUser()
789 || $wgTitle->getNamespace() == Namespace::getTalk(Namespace::getUser()) )
790
791 {
792 $id=User::idFromName($wgTitle->getText());
793 $ip=User::isIP($wgTitle->getText());
794
795 if($id || $ip) { # both anons and non-anons have contri list
796 $s .= $sep . $this->userContribsLink();
797 }
798 if ( 0 != $wgUser->getID() ) { # show only to signed in users
799 if($id) { # can only email non-anons
800 $s .= $sep . $this->emailUserLink();
801 }
802 }
803 }
804 if ( $wgTitle->getArticleId() ) {
805 $s .= "\n<br />";
806 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
807 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
808 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
809 }
810 $s .= "<br />\n" . $this->otherLanguages();
811 }
812 return $s;
813 }
814
815 function pageStats() {
816 global $wgOut, $wgLang, $wgArticle, $wgRequest;
817 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax;
818
819 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
820 if ( ! $wgOut->isArticle() ) { return ''; }
821 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
822 if ( 0 == $wgArticle->getID() ) { return ''; }
823
824 $s = '';
825 if ( !$wgDisableCounters ) {
826 $count = $wgLang->formatNum( $wgArticle->getCount() );
827 if ( $count ) {
828 $s = wfMsg( 'viewcount', $count );
829 }
830 }
831
832 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
833 require_once("Credits.php");
834 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
835 } else {
836 $s .= $this->lastModified();
837 }
838
839 return $s . ' ' . $this->getCopyright();
840 }
841
842 function getCopyright() {
843 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
844
845
846 $oldid = $wgRequest->getVal( 'oldid' );
847 $diff = $wgRequest->getVal( 'diff' );
848
849 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
850 $msg = 'history_copyright';
851 } else {
852 $msg = 'copyright';
853 }
854
855 $out = '';
856 if( $wgRightsPage ) {
857 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
858 } elseif( $wgRightsUrl ) {
859 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
860 } else {
861 # Give up now
862 return $out;
863 }
864 $out .= wfMsgForContent( $msg, $link );
865 return $out;
866 }
867
868 function getCopyrightIcon() {
869 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRightsIcon;
870 $out = '';
871 if( $wgRightsIcon ) {
872 $icon = htmlspecialchars( $wgRightsIcon );
873 if( $wgRightsUrl ) {
874 $url = htmlspecialchars( $wgRightsUrl );
875 $out .= '<a href="'.$url.'">';
876 }
877 $text = htmlspecialchars( $wgRightsText );
878 $out .= "<img src=\"$icon\" alt='$text' />";
879 if( $wgRightsUrl ) {
880 $out .= '</a>';
881 }
882 }
883 return $out;
884 }
885
886 function getPoweredBy() {
887 global $wgStylePath;
888 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
889 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
890 return $img;
891 }
892
893 function lastModified() {
894 global $wgLang, $wgArticle;
895
896 $timestamp = $wgArticle->getTimestamp();
897 if ( $timestamp ) {
898 $d = $wgLang->timeanddate( $wgArticle->getTimestamp(), true );
899 $s = ' ' . wfMsg( 'lastmodified', $d );
900 } else {
901 $s = '';
902 }
903 return $s;
904 }
905
906 function logoText( $align = '' ) {
907 if ( '' != $align ) { $a = " align='{$align}'"; }
908 else { $a = ''; }
909
910 $mp = wfMsg( 'mainpage' );
911 $titleObj = Title::newFromText( $mp );
912 if ( is_object( $titleObj ) ) {
913 $url = $titleObj->escapeLocalURL();
914 } else {
915 $url = '';
916 }
917
918 $logourl = $this->getLogo();
919 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
920 return $s;
921 }
922
923 function specialPagesList() {
924 global $wgUser, $wgOut, $wgContLang, $wgServer, $wgRedirectScript;
925 require_once('SpecialPage.php');
926 $a = array();
927 $pages = SpecialPage::getPages();
928
929 foreach ( $pages[''] as $name => $page ) {
930 $a[$name] = $page->getDescription();
931 }
932 if ( $wgUser->isSysop() )
933 {
934 foreach ( $pages['sysop'] as $name => $page ) {
935 $a[$name] = $page->getDescription();
936 }
937 }
938 if ( $wgUser->isDeveloper() )
939 {
940 foreach ( $pages['developer'] as $name => $page ) {
941 $a[$name] = $page->getDescription() ;
942 }
943 }
944 $go = wfMsg( 'go' );
945 $sp = wfMsg( 'specialpages' );
946 $spp = $wgContLang->specialPage( 'Specialpages' );
947
948 $s = '<form id="specialpages" method="get" class="inline" ' .
949 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
950 $s .= "<select name=\"wpDropdown\">\n";
951 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
952
953 foreach ( $a as $name => $desc ) {
954 $p = $wgContLang->specialPage( $name );
955 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
956 }
957 $s .= "</select>\n";
958 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
959 $s .= "</form>\n";
960 return $s;
961 }
962
963 function mainPageLink() {
964 $mp = wfMsgForContent( 'mainpage' );
965 $mptxt = wfMsg( 'mainpage');
966 $s = $this->makeKnownLink( $mp, $mptxt );
967 return $s;
968 }
969
970 function copyrightLink() {
971 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
972 wfMsg( 'copyrightpagename' ) );
973 return $s;
974 }
975
976 function aboutLink() {
977 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
978 wfMsg( 'aboutsite' ) );
979 return $s;
980 }
981
982
983 function disclaimerLink() {
984 $disclaimers = wfMsg( 'disclaimers' );
985 if ($disclaimers == '-') {
986 return "";
987 } else {
988 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
989 $disclaimers );
990 }
991 }
992
993 function editThisPage() {
994 global $wgOut, $wgTitle, $wgRequest;
995
996 $oldid = $wgRequest->getVal( 'oldid' );
997 $diff = $wgRequest->getVal( 'diff' );
998 $redirect = $wgRequest->getVal( 'redirect' );
999
1000 if ( ! $wgOut->isArticleRelated() ) {
1001 $s = wfMsg( 'protectedpage' );
1002 } else {
1003 $n = $wgTitle->getPrefixedText();
1004 if ( $wgTitle->userCanEdit() ) {
1005 $t = wfMsg( 'editthispage' );
1006 } else {
1007 #$t = wfMsg( "protectedpage" );
1008 $t = wfMsg( 'viewsource' );
1009 }
1010 $oid = $red = '';
1011
1012 if ( !is_null( $redirect ) ) { $red = "&redirect={$redirect}"; }
1013 if ( $oldid && ! isset( $diff ) ) {
1014 $oid = '&oldid='.$oldid;
1015 }
1016 $s = $this->makeKnownLink( $n, $t, "action=edit{$oid}{$red}" );
1017 }
1018 return $s;
1019 }
1020
1021 function deleteThisPage() {
1022 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1023
1024 $diff = $wgRequest->getVal( 'diff' );
1025 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1026 $n = $wgTitle->getPrefixedText();
1027 $t = wfMsg( 'deletethispage' );
1028
1029 $s = $this->makeKnownLink( $n, $t, 'action=delete' );
1030 } else {
1031 $s = '';
1032 }
1033 return $s;
1034 }
1035
1036 function protectThisPage() {
1037 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1038
1039 $diff = $wgRequest->getVal( 'diff' );
1040 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1041 $n = $wgTitle->getPrefixedText();
1042
1043 if ( $wgTitle->isProtected() ) {
1044 $t = wfMsg( 'unprotectthispage' );
1045 $q = 'action=unprotect';
1046 } else {
1047 $t = wfMsg( 'protectthispage' );
1048 $q = 'action=protect';
1049 }
1050 $s = $this->makeKnownLink( $n, $t, $q );
1051 } else {
1052 $s = '';
1053 }
1054 return $s;
1055 }
1056
1057 function watchThisPage() {
1058 global $wgUser, $wgOut, $wgTitle;
1059
1060 if ( $wgOut->isArticleRelated() ) {
1061 $n = $wgTitle->getPrefixedText();
1062
1063 if ( $wgTitle->userIsWatching() ) {
1064 $t = wfMsg( 'unwatchthispage' );
1065 $q = 'action=unwatch';
1066 } else {
1067 $t = wfMsg( 'watchthispage' );
1068 $q = 'action=watch';
1069 }
1070 $s = $this->makeKnownLink( $n, $t, $q );
1071 } else {
1072 $s = wfMsg( 'notanarticle' );
1073 }
1074 return $s;
1075 }
1076
1077 function moveThisPage() {
1078 global $wgTitle, $wgContLang;
1079
1080 if ( $wgTitle->userCanEdit() ) {
1081 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Movepage' ),
1082 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1083 } // no message if page is protected - would be redundant
1084 return $s;
1085 }
1086
1087 function historyLink() {
1088 global $wgTitle;
1089
1090 $s = $this->makeKnownLink( $wgTitle->getPrefixedText(),
1091 wfMsg( 'history' ), 'action=history' );
1092 return $s;
1093 }
1094
1095 function whatLinksHere() {
1096 global $wgTitle, $wgContLang;
1097
1098 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Whatlinkshere' ),
1099 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1100 return $s;
1101 }
1102
1103 function userContribsLink() {
1104 global $wgTitle, $wgContLang;
1105
1106 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Contributions' ),
1107 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1108 return $s;
1109 }
1110
1111 function emailUserLink() {
1112 global $wgTitle, $wgContLang;
1113
1114 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Emailuser' ),
1115 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1116 return $s;
1117 }
1118
1119 function watchPageLinksLink() {
1120 global $wgOut, $wgTitle, $wgContLang;
1121
1122 if ( ! $wgOut->isArticleRelated() ) {
1123 $s = '(' . wfMsg( 'notanarticle' ) . ')';
1124 } else {
1125 $s = $this->makeKnownLink( $wgContLang->specialPage(
1126 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1127 'target=' . $wgTitle->getPrefixedURL() );
1128 }
1129 return $s;
1130 }
1131
1132 function otherLanguages() {
1133 global $wgOut, $wgContLang, $wgTitle, $wgUseNewInterlanguage;
1134
1135 $a = $wgOut->getLanguageLinks();
1136 if ( 0 == count( $a ) ) {
1137 if ( !$wgUseNewInterlanguage ) return '';
1138 $ns = $wgContLang->getNsIndex ( $wgTitle->getNamespace () ) ;
1139 if ( $ns != 0 AND $ns != 1 ) return '' ;
1140 $pn = 'Intl' ;
1141 $x = 'mode=addlink&xt='.$wgTitle->getDBkey() ;
1142 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
1143 wfMsg( 'intl' ) , $x );
1144 }
1145
1146 if ( !$wgUseNewInterlanguage ) {
1147 $s = wfMsg( 'otherlanguages' ) . ': ';
1148 } else {
1149 global $wgContLanguageCode ;
1150 $x = 'mode=zoom&xt='.$wgTitle->getDBkey() ;
1151 $x .= '&xl='.$wgContLanguageCode ;
1152 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Intl' ),
1153 wfMsg( 'otherlanguages' ) , $x ) . ': ' ;
1154 }
1155
1156 $s = wfMsg( 'otherlanguages' ) . ': ';
1157 $first = true;
1158 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1159 foreach( $a as $l ) {
1160 if ( ! $first ) { $s .= ' | '; }
1161 $first = false;
1162
1163 $nt = Title::newFromText( $l );
1164 $url = $nt->getFullURL();
1165 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1166
1167 if ( '' == $text ) { $text = $l; }
1168 $style = $this->getExternalLinkAttributes( $l, $text );
1169 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1170 }
1171 if($wgContLang->isRTL()) $s .= '</span>';
1172 return $s;
1173 }
1174
1175 function bugReportsLink() {
1176 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1177 wfMsg( 'bugreports' ) );
1178 return $s;
1179 }
1180
1181 function dateLink() {
1182 global $wgLinkCache;
1183 $t1 = Title::newFromText( gmdate( 'F j' ) );
1184 $t2 = Title::newFromText( gmdate( 'Y' ) );
1185
1186 $wgLinkCache->suspend();
1187 $id = $t1->getArticleID();
1188 $wgLinkCache->resume();
1189
1190 if ( 0 == $id ) {
1191 $s = $this->makeBrokenLink( $t1->getText() );
1192 } else {
1193 $s = $this->makeKnownLink( $t1->getText() );
1194 }
1195 $s .= ', ';
1196
1197 $wgLinkCache->suspend();
1198 $id = $t2->getArticleID();
1199 $wgLinkCache->resume();
1200
1201 if ( 0 == $id ) {
1202 $s .= $this->makeBrokenLink( $t2->getText() );
1203 } else {
1204 $s .= $this->makeKnownLink( $t2->getText() );
1205 }
1206 return $s;
1207 }
1208
1209 function talkLink() {
1210 global $wgContLang, $wgTitle, $wgLinkCache;
1211
1212 $tns = $wgTitle->getNamespace();
1213 if ( -1 == $tns ) { return ''; }
1214
1215 $pn = $wgTitle->getText();
1216 $tp = wfMsg( 'talkpage' );
1217 if ( Namespace::isTalk( $tns ) ) {
1218 $lns = Namespace::getSubject( $tns );
1219 switch($tns) {
1220 case 1:
1221 $text = wfMsg('articlepage');
1222 break;
1223 case 3:
1224 $text = wfMsg('userpage');
1225 break;
1226 case 5:
1227 $text = wfMsg('wikipediapage');
1228 break;
1229 case 7:
1230 $text = wfMsg('imagepage');
1231 break;
1232 default:
1233 $text= wfMsg('articlepage');
1234 }
1235 } else {
1236
1237 $lns = Namespace::getTalk( $tns );
1238 $text=$tp;
1239 }
1240 $n = $wgContLang->getNsText( $lns );
1241 if ( '' == $n ) { $link = $pn; }
1242 else { $link = $n.':'.$pn; }
1243
1244 $wgLinkCache->suspend();
1245 $s = $this->makeLink( $link, $text );
1246 $wgLinkCache->resume();
1247
1248 return $s;
1249 }
1250
1251 function commentLink() {
1252 global $wgContLang, $wgTitle, $wgLinkCache;
1253
1254 $tns = $wgTitle->getNamespace();
1255 if ( -1 == $tns ) { return ''; }
1256
1257 $lns = ( Namespace::isTalk( $tns ) ) ? $tns : Namespace::getTalk( $tns );
1258
1259 # assert Namespace::isTalk( $lns )
1260
1261 $n = $wgContLang->getNsText( $lns );
1262 $pn = $wgTitle->getText();
1263
1264 $link = $n.':'.$pn;
1265
1266 $wgLinkCache->suspend();
1267 $s = $this->makeKnownLink($link, wfMsg('postcomment'), 'action=edit&section=new');
1268 $wgLinkCache->resume();
1269
1270 return $s;
1271 }
1272
1273 /**
1274 * After all the page content is transformed into HTML, it makes
1275 * a final pass through here for things like table backgrounds.
1276 * @todo probably deprecated [AV]
1277 */
1278 function transformContent( $text ) {
1279 return $text;
1280 }
1281
1282 /**
1283 * Note: This function MUST call getArticleID() on the link,
1284 * otherwise the cache won't get updated properly. See LINKCACHE.DOC.
1285 */
1286 function makeLink( $title, $text = '', $query = '', $trail = '' ) {
1287 wfProfileIn( 'Skin::makeLink' );
1288 $nt = Title::newFromText( $title );
1289 if ($nt) {
1290 $result = $this->makeLinkObj( Title::newFromText( $title ), $text, $query, $trail );
1291 } else {
1292 wfDebug( 'Invalid title passed to Skin::makeLink(): "'.$title."\"\n" );
1293 $result = $text == "" ? $title : $text;
1294 }
1295
1296 wfProfileOut( 'Skin::makeLink' );
1297 return $result;
1298 }
1299
1300 function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
1301 $nt = Title::newFromText( $title );
1302 if ($nt) {
1303 return $this->makeKnownLinkObj( Title::newFromText( $title ), $text, $query, $trail, $prefix , $aprops );
1304 } else {
1305 wfDebug( 'Invalid title passed to Skin::makeKnownLink(): "'.$title."\"\n" );
1306 return $text == '' ? $title : $text;
1307 }
1308 }
1309
1310 function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
1311 $nt = Title::newFromText( $title );
1312 if ($nt) {
1313 return $this->makeBrokenLinkObj( Title::newFromText( $title ), $text, $query, $trail );
1314 } else {
1315 wfDebug( 'Invalid title passed to Skin::makeBrokenLink(): "'.$title."\"\n" );
1316 return $text == '' ? $title : $text;
1317 }
1318 }
1319
1320 function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
1321 $nt = Title::newFromText( $title );
1322 if ($nt) {
1323 return $this->makeStubLinkObj( Title::newFromText( $title ), $text, $query, $trail );
1324 } else {
1325 wfDebug( 'Invalid title passed to Skin::makeStubLink(): "'.$title."\"\n" );
1326 return $text == '' ? $title : $text;
1327 }
1328 }
1329
1330 /**
1331 * Pass a title object, not a title string
1332 */
1333 function makeLinkObj( &$nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
1334 global $wgOut, $wgUser, $wgLinkHolders;
1335 $fname = 'Skin::makeLinkObj';
1336
1337 # Fail gracefully
1338 if ( ! isset($nt) ) {
1339 # wfDebugDieBacktrace();
1340 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
1341 }
1342
1343 if ( $nt->isExternal() ) {
1344 $u = $nt->getFullURL();
1345 $link = $nt->getPrefixedURL();
1346 if ( '' == $text ) { $text = $nt->getPrefixedText(); }
1347 $style = $this->getExternalLinkAttributes( $link, $text, 'extiw' );
1348
1349 $inside = '';
1350 if ( '' != $trail ) {
1351 if ( preg_match( '/^([a-z]+)(.*)$$/sD', $trail, $m ) ) {
1352 $inside = $m[1];
1353 $trail = $m[2];
1354 }
1355 }
1356 # Assume $this->postParseLinkColour(). This prevents
1357 # interwiki links from being parsed as external links.
1358 global $wgInterwikiLinkHolders;
1359 $t = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>";
1360 $nr = array_push($wgInterwikiLinkHolders, $t);
1361 $retVal = '<!--IWLINK '. ($nr-1) ."-->{$trail}";
1362 } elseif ( 0 == $nt->getNamespace() && "" == $nt->getText() ) {
1363 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
1364 } elseif ( ( -1 == $nt->getNamespace() ) ||
1365 ( NS_IMAGE == $nt->getNamespace() ) ) {
1366 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
1367 } else {
1368 if ( $this->postParseLinkColour() ) {
1369 $inside = '';
1370 if ( '' != $trail ) {
1371 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1372 $inside = $m[1];
1373 $trail = $m[2];
1374 }
1375 }
1376
1377 # Allows wiki to bypass using linkcache, see OutputPage::parseLinkHolders()
1378 $nr = array_push( $wgLinkHolders['namespaces'], $nt->getNamespace() );
1379 $wgLinkHolders['dbkeys'][] = $nt->getDBkey();
1380 $wgLinkHolders['queries'][] = $query;
1381 $wgLinkHolders['texts'][] = $prefix.$text.$inside;
1382 $wgLinkHolders['titles'][] = $nt;
1383
1384 $retVal = '<!--LINK '. ($nr-1) ."-->{$trail}";
1385 } else {
1386 # Work out link colour immediately
1387 $aid = $nt->getArticleID() ;
1388 if ( 0 == $aid ) {
1389 $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix );
1390 } else {
1391 $threshold = $wgUser->getOption('stubthreshold') ;
1392 if ( $threshold > 0 ) {
1393 $dbr =& wfGetDB( DB_SLAVE );
1394 $s = $dbr->selectRow( 'cur', array( 'LENGTH(cur_text) AS x', 'cur_namespace',
1395 'cur_is_redirect' ), array( 'cur_id' => $aid ), $fname ) ;
1396 if ( $s !== false ) {
1397 $size = $s->x;
1398 if ( $s->cur_is_redirect OR $s->cur_namespace != 0 ) {
1399 $size = $threshold*2 ; # Really big
1400 }
1401 $dbr->freeResult( $res );
1402 } else {
1403 $size = $threshold*2 ; # Really big
1404 }
1405 } else {
1406 $size = 1 ;
1407 }
1408 if ( $size < $threshold ) {
1409 $retVal = $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix );
1410 } else {
1411 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
1412 }
1413 }
1414 }
1415 }
1416 return $retVal;
1417 }
1418
1419 /**
1420 * Pass a title object, not a title string
1421 */
1422 function makeKnownLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '' ) {
1423 global $wgOut, $wgTitle, $wgInputEncoding;
1424
1425 $fname = 'Skin::makeKnownLinkObj';
1426 wfProfileIn( $fname );
1427
1428 if ( !is_object( $nt ) ) {
1429 return $text;
1430 }
1431 $link = $nt->getPrefixedURL();
1432 # if ( '' != $section && substr($section,0,1) != "#" ) {
1433 # $section = ''
1434
1435 if ( '' == $link ) {
1436 $u = '';
1437 if ( '' == $text ) {
1438 $text = htmlspecialchars( $nt->getFragment() );
1439 }
1440 } else {
1441 $u = $nt->escapeLocalURL( $query );
1442 }
1443 if ( '' != $nt->getFragment() ) {
1444 $anchor = urlencode( do_html_entity_decode( str_replace(' ', '_', $nt->getFragment()), ENT_COMPAT, $wgInputEncoding ) );
1445 $replacearray = array(
1446 '%3A' => ':',
1447 '%' => '.'
1448 );
1449 $u .= '#' . str_replace(array_keys($replacearray),array_values($replacearray),$anchor);
1450 }
1451 if ( '' == $text ) {
1452 $text = htmlspecialchars( $nt->getPrefixedText() );
1453 }
1454 $style = $this->getInternalLinkAttributesObj( $nt, $text );
1455
1456 $inside = '';
1457 if ( '' != $trail ) {
1458 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1459 $inside = $m[1];
1460 $trail = $m[2];
1461 }
1462 }
1463 $r = "<a href=\"{$u}\"{$style}{$aprops}>{$prefix}{$text}{$inside}</a>{$trail}";
1464 wfProfileOut( $fname );
1465 return $r;
1466 }
1467
1468 /**
1469 * Pass a title object, not a title string
1470 */
1471 function makeBrokenLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1472 global $wgOut, $wgUser;
1473
1474 # Fail gracefully
1475 if ( ! isset($nt) ) {
1476 # wfDebugDieBacktrace();
1477 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
1478 }
1479
1480 $fname = 'Skin::makeBrokenLinkObj';
1481 wfProfileIn( $fname );
1482
1483 if ( '' == $query ) {
1484 $q = 'action=edit';
1485 } else {
1486 $q = 'action=edit&'.$query;
1487 }
1488 $u = $nt->escapeLocalURL( $q );
1489
1490 if ( '' == $text ) {
1491 $text = htmlspecialchars( $nt->getPrefixedText() );
1492 }
1493 $style = $this->getInternalLinkAttributesObj( $nt, $text, "yes" );
1494
1495 $inside = '';
1496 if ( '' != $trail ) {
1497 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1498 $inside = $m[1];
1499 $trail = $m[2];
1500 }
1501 }
1502 if ( $wgUser->getOption( 'highlightbroken' ) ) {
1503 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
1504 } else {
1505 $s = "{$prefix}{$text}{$inside}<a href=\"{$u}\"{$style}>?</a>{$trail}";
1506 }
1507
1508 wfProfileOut( $fname );
1509 return $s;
1510 }
1511
1512 /**
1513 * Pass a title object, not a title string
1514 */
1515 function makeStubLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1516 global $wgOut, $wgUser;
1517
1518 $link = $nt->getPrefixedURL();
1519
1520 $u = $nt->escapeLocalURL( $query );
1521
1522 if ( '' == $text ) {
1523 $text = htmlspecialchars( $nt->getPrefixedText() );
1524 }
1525 $style = $this->getInternalLinkAttributesObj( $nt, $text, 'stub' );
1526
1527 $inside = '';
1528 if ( '' != $trail ) {
1529 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1530 $inside = $m[1];
1531 $trail = $m[2];
1532 }
1533 }
1534 if ( $wgUser->getOption( 'highlightbroken' ) ) {
1535 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
1536 } else {
1537 $s = "{$prefix}{$text}{$inside}<a href=\"{$u}\"{$style}>!</a>{$trail}";
1538 }
1539 return $s;
1540 }
1541
1542 function makeSelfLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1543 $u = $nt->escapeLocalURL( $query );
1544 if ( '' == $text ) {
1545 $text = htmlspecialchars( $nt->getPrefixedText() );
1546 }
1547 $inside = '';
1548 if ( '' != $trail ) {
1549 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1550 $inside = $m[1];
1551 $trail = $m[2];
1552 }
1553 }
1554 return "<strong>{$prefix}{$text}{$inside}</strong>{$trail}";
1555 }
1556
1557 /* these are used extensively in SkinPHPTal, but also some other places */
1558 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
1559 $title = Title::makeTitle( NS_SPECIAL, $name );
1560 $this->checkTitle($title, $name);
1561 return $title->getLocalURL( $urlaction );
1562 }
1563 /*static*/ function makeTalkUrl ( $name, $urlaction='' ) {
1564 $title = Title::newFromText( $name );
1565 $title = $title->getTalkPage();
1566 $this->checkTitle($title, $name);
1567 return $title->getLocalURL( $urlaction );
1568 }
1569 /*static*/ function makeArticleUrl ( $name, $urlaction='' ) {
1570 $title = Title::newFromText( $name );
1571 $title= $title->getSubjectPage();
1572 $this->checkTitle($title, $name);
1573 return $title->getLocalURL( $urlaction );
1574 }
1575 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
1576 $title = Title::newFromText( wfMsgForContent($name) );
1577 $this->checkTitle($title, $name);
1578 return $title->getLocalURL( $urlaction );
1579 }
1580 /*static*/ function makeUrl ( $name, $urlaction='' ) {
1581 $title = Title::newFromText( $name );
1582 $this->checkTitle($title, $name);
1583 return $title->getLocalURL( $urlaction );
1584 }
1585
1586 # If url string starts with http, consider as external URL, else
1587 # internal
1588 /*static*/ function makeInternalOrExternalUrl( $name ) {
1589 if ( strncmp( $name, 'http', 4 ) == 0 ) {
1590 return $name;
1591 } else {
1592 return $this->makeUrl( $name );
1593 }
1594 }
1595
1596 # this can be passed the NS number as defined in Language.php
1597 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=0 ) {
1598 $title = Title::makeTitleSafe( $namespace, $name );
1599 $this->checkTitle($title, $name);
1600 return $title->getLocalURL( $urlaction );
1601 }
1602
1603 /* these return an array with the 'href' and boolean 'exists' */
1604 /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
1605 $title = Title::newFromText( $name );
1606 $this->checkTitle($title, $name);
1607 return array(
1608 'href' => $title->getLocalURL( $urlaction ),
1609 'exists' => $title->getArticleID() != 0?true:false
1610 );
1611 }
1612 /*static*/ function makeTalkUrlDetails ( $name, $urlaction='' ) {
1613 $title = Title::newFromText( $name );
1614 $title = $title->getTalkPage();
1615 $this->checkTitle($title, $name);
1616 return array(
1617 'href' => $title->getLocalURL( $urlaction ),
1618 'exists' => $title->getArticleID() != 0?true:false
1619 );
1620 }
1621 /*static*/ function makeArticleUrlDetails ( $name, $urlaction='' ) {
1622 $title = Title::newFromText( $name );
1623 $title= $title->getSubjectPage();
1624 $this->checkTitle($title, $name);
1625 return array(
1626 'href' => $title->getLocalURL( $urlaction ),
1627 'exists' => $title->getArticleID() != 0?true:false
1628 );
1629 }
1630 /*static*/ function makeI18nUrlDetails ( $name, $urlaction='' ) {
1631 $title = Title::newFromText( wfMsgForContent($name) );
1632 $this->checkTitle($title, $name);
1633 return array(
1634 'href' => $title->getLocalURL( $urlaction ),
1635 'exists' => $title->getArticleID() != 0?true:false
1636 );
1637 }
1638
1639 # make sure we have some title to operate on
1640 /*static*/ function checkTitle ( &$title, &$name ) {
1641 if(!is_object($title)) {
1642 $title = Title::newFromText( $name );
1643 if(!is_object($title)) {
1644 $title = Title::newFromText( '--error: link target missing--' );
1645 }
1646 }
1647 }
1648
1649 function fnamePart( $url ) {
1650 $basename = strrchr( $url, '/' );
1651 if ( false === $basename ) {
1652 $basename = $url;
1653 } else {
1654 $basename = substr( $basename, 1 );
1655 }
1656 return htmlspecialchars( $basename );
1657 }
1658
1659 function makeImage( $url, $alt = '' ) {
1660 global $wgOut;
1661 if ( '' == $alt ) {
1662 $alt = $this->fnamePart( $url );
1663 }
1664 $s = '<img src="'.$url.'" alt="'.$alt.'" />';
1665 return $s;
1666 }
1667
1668 function makeImageLink( $name, $url, $alt = '' ) {
1669 $nt = Title::makeTitleSafe( NS_IMAGE, $name );
1670 return $this->makeImageLinkObj( $nt, $alt );
1671 }
1672
1673 function makeImageLinkObj( $nt, $alt = '' ) {
1674 global $wgContLang, $wgUseImageResize;
1675 $img = Image::newFromTitle( $nt );
1676 $url = $img->getViewURL();
1677
1678 $align = '';
1679 $prefix = $postfix = '';
1680
1681 # Check if the alt text is of the form "options|alt text"
1682 # Options are:
1683 # * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang
1684 # * left no resizing, just left align. label is used for alt= only
1685 # * right same, but right aligned
1686 # * none same, but not aligned
1687 # * ___px scale to ___ pixels width, no aligning. e.g. use in taxobox
1688 # * center center the image
1689 # * framed Keep original image size, no magnify-button.
1690
1691 $part = explode( '|', $alt);
1692
1693 $mwThumb =& MagicWord::get( MAG_IMG_THUMBNAIL );
1694 $mwLeft =& MagicWord::get( MAG_IMG_LEFT );
1695 $mwRight =& MagicWord::get( MAG_IMG_RIGHT );
1696 $mwNone =& MagicWord::get( MAG_IMG_NONE );
1697 $mwWidth =& MagicWord::get( MAG_IMG_WIDTH );
1698 $mwCenter =& MagicWord::get( MAG_IMG_CENTER );
1699 $mwFramed =& MagicWord::get( MAG_IMG_FRAMED );
1700 $alt = '';
1701
1702 $height = $framed = $thumb = false;
1703 $manual_thumb = "" ;
1704
1705 foreach( $part as $key => $val ) {
1706 $val_parts = explode ( "=" , $val , 2 ) ;
1707 $left_part = array_shift ( $val_parts ) ;
1708 if ( $wgUseImageResize && ! is_null( $mwThumb->matchVariableStartToEnd($val) ) ) {
1709 $thumb=true;
1710 } elseif ( $wgUseImageResize && count ( $val_parts ) == 1 && ! is_null( $mwThumb->matchVariableStartToEnd($left_part) ) ) {
1711 # use manually specified thumbnail
1712 $thumb=true;
1713 $manual_thumb = array_shift ( $val_parts ) ;
1714 } elseif ( ! is_null( $mwRight->matchVariableStartToEnd($val) ) ) {
1715 # remember to set an alignment, don't render immediately
1716 $align = 'right';
1717 } elseif ( ! is_null( $mwLeft->matchVariableStartToEnd($val) ) ) {
1718 # remember to set an alignment, don't render immediately
1719 $align = 'left';
1720 } elseif ( ! is_null( $mwCenter->matchVariableStartToEnd($val) ) ) {
1721 # remember to set an alignment, don't render immediately
1722 $align = 'center';
1723 } elseif ( ! is_null( $mwNone->matchVariableStartToEnd($val) ) ) {
1724 # remember to set an alignment, don't render immediately
1725 $align = 'none';
1726 } elseif ( $wgUseImageResize && ! is_null( $match = $mwWidth->matchVariableStartToEnd($val) ) ) {
1727 # $match is the image width in pixels
1728 if ( preg_match( '/^([0-9]*)x([0-9]*)$/', $match, $m ) ) {
1729 $width = intval( $m[1] );
1730 $height = intval( $m[2] );
1731 } else {
1732 $width = intval($match);
1733 }
1734 } elseif ( ! is_null( $mwFramed->matchVariableStartToEnd($val) ) ) {
1735 $framed=true;
1736 } else {
1737 $alt = $val;
1738 }
1739 }
1740 if ( 'center' == $align )
1741 {
1742 $prefix = '<div class="center">';
1743 $postfix = '</div>';
1744 $align = 'none';
1745 }
1746
1747 if ( $thumb || $framed ) {
1748
1749 # Create a thumbnail. Alignment depends on language
1750 # writing direction, # right aligned for left-to-right-
1751 # languages ("Western languages"), left-aligned
1752 # for right-to-left-languages ("Semitic languages")
1753 #
1754 # If thumbnail width has not been provided, it is set
1755 # here to 180 pixels
1756 if ( $align == '' ) {
1757 $align = $wgContLang->isRTL() ? 'left' : 'right';
1758 }
1759 if ( ! isset($width) ) {
1760 $width = 180;
1761 }
1762 return $prefix.$this->makeThumbLinkObj( $img, $alt, $align, $width, $height, $framed, $manual_thumb ).$postfix;
1763
1764 } elseif ( isset($width) ) {
1765
1766 # Create a resized image, without the additional thumbnail
1767 # features
1768
1769 if ( ( ! $height === false )
1770 && ( $img->getHeight() * $width / $img->getWidth() > $height ) ) {
1771 $width = $img->getWidth() * $height / $img->getHeight();
1772 }
1773 if ( '' == $manual_thumb ) $url = $img->createThumb( $width );
1774 }
1775
1776 $alt = preg_replace( '/<[^>]*>/', '', $alt );
1777 $alt = preg_replace('/&(?!:amp;|#[Xx][0-9A-fa-f]+;|#[0-9]+;|[a-zA-Z0-9]+;)/', '&amp;', $alt);
1778 $alt = str_replace( array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $alt );
1779
1780 $u = $nt->escapeLocalURL();
1781 if ( $url == '' ) {
1782 $s = wfMsg( 'missingimage', $img->getName() );
1783 $s .= "<br>{$alt}<br>{$url}<br>\n";
1784 } else {
1785 $s = '<a href="'.$u.'" class="image" title="'.$alt.'">' .
1786 '<img src="'.$url.'" alt="'.$alt.'" longdesc="'.$u.'" /></a>';
1787 }
1788 if ( '' != $align ) {
1789 $s = "<div class=\"float{$align}\"><span>{$s}</span></div>";
1790 }
1791 return str_replace("\n", ' ',$prefix.$s.$postfix);
1792 }
1793
1794 /**
1795 * Make HTML for a thumbnail including image, border and caption
1796 * $img is an Image object
1797 */
1798 function makeThumbLinkObj( $img, $label = '', $align = 'right', $boxwidth = 180, $boxheight=false, $framed=false , $manual_thumb = "" ) {
1799 global $wgStylePath, $wgContLang;
1800 # $image = Title::makeTitleSafe( NS_IMAGE, $name );
1801 $url = $img->getViewURL();
1802
1803 #$label = htmlspecialchars( $label );
1804 $alt = preg_replace( '/<[^>]*>/', '', $label);
1805 $alt = preg_replace('/&(?!:amp;|#[Xx][0-9A-fa-f]+;|#[0-9]+;|[a-zA-Z0-9]+;)/', '&amp;', $alt);
1806 $alt = str_replace( array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $alt );
1807
1808 $width = $height = 0;
1809 if ( $img->exists() )
1810 {
1811 $width = $img->getWidth();
1812 $height = $img->getHeight();
1813 }
1814 if ( 0 == $width || 0 == $height )
1815 {
1816 $width = $height = 200;
1817 }
1818 if ( $boxwidth == 0 )
1819 {
1820 $boxwidth = 200;
1821 }
1822 if ( $framed )
1823 {
1824 // Use image dimensions, don't scale
1825 $boxwidth = $width;
1826 $oboxwidth = $boxwidth + 2;
1827 $boxheight = $height;
1828 $thumbUrl = $url;
1829 } else {
1830 $h = intval( $height/($width/$boxwidth) );
1831 $oboxwidth = $boxwidth + 2;
1832 if ( ( ! $boxheight === false ) && ( $h > $boxheight ) )
1833 {
1834 $boxwidth *= $boxheight/$h;
1835 } else {
1836 $boxheight = $h;
1837 }
1838 if ( '' == $manual_thumb ) $thumbUrl = $img->createThumb( $boxwidth );
1839 }
1840
1841 if ( $manual_thumb != '' ) # Use manually specified thumbnail
1842 {
1843 $manual_title = Title::makeTitleSafe( NS_IMAGE, $manual_thumb ); #new Title ( $manual_thumb ) ;
1844 $manual_img = Image::newFromTitle( $manual_title );
1845 $thumbUrl = $manual_img->getViewURL();
1846 if ( $manual_img->exists() )
1847 {
1848 $width = $manual_img->getWidth();
1849 $height = $manual_img->getHeight();
1850 $boxwidth = $width ;
1851 $boxheight = $height ;
1852 $oboxwidth = $boxwidth + 2 ;
1853 }
1854 }
1855
1856 $u = $img->getEscapeLocalURL();
1857
1858 $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
1859 $magnifyalign = $wgContLang->isRTL() ? 'left' : 'right';
1860 $textalign = $wgContLang->isRTL() ? ' style="text-align:right"' : '';
1861
1862 $s = "<div class=\"thumb t{$align}\"><div style=\"width:{$oboxwidth}px;\">";
1863 if ( $thumbUrl == '' ) {
1864 $s .= wfMsg( 'missingimage', $img->getName() );
1865 $zoomicon = '';
1866 } else {
1867 $s .= '<a href="'.$u.'" class="internal" title="'.$alt.'">'.
1868 '<img src="'.$thumbUrl.'" alt="'.$alt.'" ' .
1869 'width="'.$boxwidth.'" height="'.$boxheight.'" ' .
1870 'longdesc="'.$u.'" /></a>';
1871 if ( $framed ) {
1872 $zoomicon="";
1873 } else {
1874 $zoomicon = '<div class="magnify" style="float:'.$magnifyalign.'">'.
1875 '<a href="'.$u.'" class="internal" title="'.$more.'">'.
1876 '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
1877 'width="15" height="11" alt="'.$more.'" /></a></div>';
1878 }
1879 }
1880 $s .= ' <div class="thumbcaption" '.$textalign.'>'.$zoomicon.$label."</div></div></div>";
1881 return str_replace("\n", ' ', $s);
1882 }
1883
1884 function makeMediaLink( $name, $url, $alt = '' ) {
1885 $nt = Title::makeTitleSafe( NS_IMAGE, $name );
1886 return $this->makeMediaLinkObj( $nt, $alt );
1887 }
1888
1889 function makeMediaLinkObj( $nt, $alt = '', $nourl=false ) {
1890 if ( ! isset( $nt ) )
1891 {
1892 ### HOTFIX. Instead of breaking, return empty string.
1893 $s = $alt;
1894 } else {
1895 $name = $nt->getDBKey();
1896 $img = Image::newFromTitle( $nt );
1897 $url = $img->getURL();
1898 # $nourl can be set by the parser
1899 # this is a hack to mask absolute URLs, so the parser doesn't
1900 # linkify them (it is currently not context-aware)
1901 # 2004-10-25
1902 if ($nourl) { $url=str_replace("http://","http-noparse://",$url) ; }
1903 if ( empty( $alt ) ) {
1904 $alt = preg_replace( '/\.(.+?)^/', '', $name );
1905 }
1906 $u = htmlspecialchars( $url );
1907 $s = "<a href=\"{$u}\" class='internal' title=\"{$alt}\">{$alt}</a>";
1908 }
1909 return $s;
1910 }
1911
1912 function specialLink( $name, $key = '' ) {
1913 global $wgContLang;
1914
1915 if ( '' == $key ) { $key = strtolower( $name ); }
1916 $pn = $wgContLang->ucfirst( $name );
1917 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
1918 wfMsg( $key ) );
1919 }
1920
1921 function makeExternalLink( $url, $text, $escape = true ) {
1922 $style = $this->getExternalLinkAttributes( $url, $text );
1923 $url = htmlspecialchars( $url );
1924 if( $escape ) {
1925 $text = htmlspecialchars( $text );
1926 }
1927 return '<a href="'.$url.'"'.$style.'>'.$text.'</a>';
1928 }
1929
1930 # Called by history lists and recent changes
1931 #
1932
1933 # Returns text for the start of the tabular part of RC
1934 function beginRecentChangesList() {
1935 $this->rc_cache = array() ;
1936 $this->rcMoveIndex = 0;
1937 $this->rcCacheIndex = 0 ;
1938 $this->lastdate = '';
1939 $this->rclistOpen = false;
1940 return '';
1941 }
1942
1943 function beginImageHistoryList() {
1944 $s = "\n<h2>" . wfMsg( 'imghistory' ) . "</h2>\n" .
1945 "<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
1946 return $s;
1947 }
1948
1949 /**
1950 * Returns text for the end of RC
1951 * If enhanced RC is in use, returns pretty much all the text
1952 */
1953 function endRecentChangesList() {
1954 $s = $this->recentChangesBlock() ;
1955 if( $this->rclistOpen ) {
1956 $s .= "</ul>\n";
1957 }
1958 return $s;
1959 }
1960
1961 /**
1962 * Enhanced RC ungrouped line
1963 */
1964 function recentChangesBlockLine ( $rcObj ) {
1965 global $wgStylePath, $wgContLang ;
1966
1967 # Get rc_xxxx variables
1968 extract( $rcObj->mAttribs ) ;
1969 $curIdEq = 'curid='.$rc_cur_id;
1970
1971 # Spacer image
1972 $r = '' ;
1973
1974 $r .= '<img src="'.$wgStylePath.'/common/images/Arr_.png" width="12" height="12" border="0" />' ;
1975 $r .= '<tt>' ;
1976
1977 if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
1978 $r .= '&nbsp;&nbsp;';
1979 } else {
1980 # M, N and !
1981 $M = wfMsg( 'minoreditletter' );
1982 $N = wfMsg( 'newpageletter' );
1983
1984 if ( $rc_type == RC_NEW ) {
1985 $r .= $N ;
1986 } else {
1987 $r .= '&nbsp;' ;
1988 }
1989 if ( $rc_minor ) {
1990 $r .= $M ;
1991 } else {
1992 $r .= '&nbsp;' ;
1993 }
1994 if ( $rcObj->unpatrolled ) {
1995 $r .= '!';
1996 } else {
1997 $r .= '&nbsp;';
1998 }
1999 }
2000
2001 # Timestamp
2002 $r .= ' '.$rcObj->timestamp.' ' ;
2003 $r .= '</tt>' ;
2004
2005 # Article link
2006 $link = $rcObj->link ;
2007 if ( $rcObj->watched ) $link = '<strong>'.$link.'</strong>' ;
2008 $r .= $link ;
2009
2010 # Diff
2011 $r .= ' (' ;
2012 $r .= $rcObj->difflink ;
2013 $r .= '; ' ;
2014
2015 # Hist
2016 $r .= $this->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' );
2017
2018 # User/talk
2019 $r .= ') . . '.$rcObj->userlink ;
2020 $r .= $rcObj->usertalklink ;
2021
2022 # Comment
2023 if ( $rc_comment != '' && $rc_type != RC_MOVE && $rc_type != RC_MOVE_OVER_REDIRECT ) {
2024 $rc_comment=$this->formatComment($rc_comment, $rcObj->getTitle());
2025 $r .= $wgContLang->emphasize( ' ('.$rc_comment.')' );
2026 }
2027
2028 $r .= "<br />\n" ;
2029 return $r ;
2030 }
2031
2032 /**
2033 * Enhanced RC group
2034 */
2035 function recentChangesBlockGroup ( $block ) {
2036 global $wgStylePath, $wgContLang ;
2037
2038 $r = '' ;
2039 $M = wfMsg( 'minoreditletter' );
2040 $N = wfMsg( 'newpageletter' );
2041
2042 # Collate list of users
2043 $isnew = false ;
2044 $unpatrolled = false;
2045 $userlinks = array () ;
2046 foreach ( $block AS $rcObj ) {
2047 $oldid = $rcObj->mAttribs['rc_last_oldid'];
2048 if ( $rcObj->mAttribs['rc_new'] ) {
2049 $isnew = true ;
2050 }
2051 $u = $rcObj->userlink ;
2052 if ( !isset ( $userlinks[$u] ) ) {
2053 $userlinks[$u] = 0 ;
2054 }
2055 if ( $rcObj->unpatrolled ) {
2056 $unpatrolled = true;
2057 }
2058 $userlinks[$u]++ ;
2059 }
2060
2061 # Sort the list and convert to text
2062 krsort ( $userlinks ) ;
2063 asort ( $userlinks ) ;
2064 $users = array () ;
2065 foreach ( $userlinks as $userlink => $count) {
2066 $text = $userlink ;
2067 if ( $count > 1 ) $text .= " ({$count}&times;)" ;
2068 array_push ( $users , $text ) ;
2069 }
2070 $users = ' <font size="-1">['.implode('; ',$users).']</font>' ;
2071
2072 # Arrow
2073 $rci = 'RCI'.$this->rcCacheIndex ;
2074 $rcl = 'RCL'.$this->rcCacheIndex ;
2075 $rcm = 'RCM'.$this->rcCacheIndex ;
2076 $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')" ;
2077 $arrowdir = $wgContLang->isRTL() ? 'l' : 'r';
2078 $tl = '<span id="'.$rcm.'"><a href="'.$toggleLink.'"><img src="'.$wgStylePath.'/common/images/Arr_'.$arrowdir.'.png" width="12" height="12" alt="+" /></a></span>' ;
2079 $tl .= '<span id="'.$rcl.'" style="display:none"><a href="'.$toggleLink.'"><img src="'.$wgStylePath.'/common/images/Arr_d.png" width="12" height="12" alt="-" /></a></span>' ;
2080 $r .= $tl ;
2081
2082 # Main line
2083 # M/N
2084 $r .= '<tt>' ;
2085 if ( $isnew ) $r .= $N ;
2086 else $r .= '&nbsp;' ;
2087 $r .= '&nbsp;' ; # Minor
2088 if ( $unpatrolled ) {
2089 $r .= "!";
2090 } else {
2091 $r .= "&nbsp;";
2092 }
2093
2094 # Timestamp
2095 $r .= ' '.$block[0]->timestamp.' ' ;
2096 $r .= '</tt>' ;
2097
2098 # Article link
2099 $link = $block[0]->link ;
2100 if ( $block[0]->watched ) $link = '<strong>'.$link.'</strong>' ;
2101 $r .= $link ;
2102
2103 $curIdEq = 'curid=' . $block[0]->mAttribs['rc_cur_id'];
2104 if ( $block[0]->mAttribs['rc_type'] != RC_LOG ) {
2105 # Changes
2106 $r .= ' ('.count($block).' ' ;
2107 if ( $isnew ) $r .= wfMsg('changes');
2108 else $r .= $this->makeKnownLinkObj( $block[0]->getTitle() , wfMsg('changes') ,
2109 $curIdEq.'&diff=0&oldid='.$oldid ) ;
2110 $r .= '; ' ;
2111
2112 # History
2113 $r .= $this->makeKnownLinkObj( $block[0]->getTitle(), wfMsg( 'history' ), $curIdEq.'&action=history' );
2114 $r .= ')' ;
2115 }
2116
2117 $r .= $users ;
2118 $r .= "<br />\n" ;
2119
2120 # Sub-entries
2121 $r .= '<div id="'.$rci.'" style="display:none">' ;
2122 foreach ( $block AS $rcObj ) {
2123 # Get rc_xxxx variables
2124 extract( $rcObj->mAttribs );
2125
2126 $r .= '<img src="'.$wgStylePath.'/common/images/Arr_.png" width="12" height="12" />';
2127 $r .= '<tt>&nbsp; &nbsp; &nbsp; &nbsp;' ;
2128 if ( $rc_new ) {
2129 $r .= $N ;
2130 } else {
2131 $r .= '&nbsp;' ;
2132 }
2133
2134 if ( $rc_minor ) {
2135 $r .= $M ;
2136 } else {
2137 $r .= '&nbsp;' ;
2138 }
2139
2140 if ( $rcObj->unpatrolled ) {
2141 $r .= "!";
2142 } else {
2143 $r .= "&nbsp;";
2144 }
2145
2146 $r .= '&nbsp;</tt>' ;
2147
2148 $o = '' ;
2149 if ( $rc_last_oldid != 0 ) {
2150 $o = 'oldid='.$rc_last_oldid ;
2151 }
2152 if ( $rc_type == RC_LOG ) {
2153 $link = $rcObj->timestamp ;
2154 } else {
2155 $link = $this->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp , "{$curIdEq}&$o" ) ;
2156 }
2157 $link = '<tt>'.$link.'</tt>' ;
2158
2159 $r .= $link ;
2160 $r .= ' (' ;
2161 $r .= $rcObj->curlink ;
2162 $r .= '; ' ;
2163 $r .= $rcObj->lastlink ;
2164 $r .= ') . . '.$rcObj->userlink ;
2165 $r .= $rcObj->usertalklink ;
2166 if ( $rc_comment != '' ) {
2167 $rc_comment=$this->formatComment($rc_comment, $rcObj->getTitle());
2168 $r .= $wgContLang->emphasize( ' ('.$rc_comment.')' ) ;
2169 }
2170 $r .= "<br />\n" ;
2171 }
2172 $r .= "</div>\n" ;
2173
2174 $this->rcCacheIndex++ ;
2175 return $r ;
2176 }
2177
2178 /**
2179 * If enhanced RC is in use, this function takes the previously cached
2180 * RC lines, arranges them, and outputs the HTML
2181 */
2182 function recentChangesBlock () {
2183 global $wgStylePath ;
2184 if ( count ( $this->rc_cache ) == 0 ) return '' ;
2185 $blockOut = '';
2186 foreach ( $this->rc_cache AS $secureName => $block ) {
2187 if ( count ( $block ) < 2 ) {
2188 $blockOut .= $this->recentChangesBlockLine ( array_shift ( $block ) ) ;
2189 } else {
2190 $blockOut .= $this->recentChangesBlockGroup ( $block ) ;
2191 }
2192 }
2193
2194 return '<div>'.$blockOut.'</div>' ;
2195 }
2196
2197 /**
2198 * Called in a loop over all displayed RC entries
2199 * Either returns the line, or caches it for later use
2200 */
2201 function recentChangesLine( &$rc, $watched = false ) {
2202 global $wgUser ;
2203 $usenew = $wgUser->getOption( 'usenewrc' );
2204 if ( $usenew )
2205 $line = $this->recentChangesLineNew ( $rc, $watched ) ;
2206 else
2207 $line = $this->recentChangesLineOld ( $rc, $watched ) ;
2208 return $line ;
2209 }
2210
2211 function recentChangesLineOld( &$rc, $watched = false ) {
2212 global $wgTitle, $wgLang, $wgContLang, $wgUser, $wgRCSeconds, $wgUseRCPatrol, $wgOnlySysopsCanPatrol;
2213
2214 # Extract DB fields into local scope
2215 extract( $rc->mAttribs );
2216 $curIdEq = 'curid=' . $rc_cur_id;
2217
2218 # Should patrol-related stuff be shown?
2219 $unpatrolled = $wgUseRCPatrol && $wgUser->getID() != 0 &&
2220 ( !$wgOnlySysopsCanPatrol || $wgUser->isAllowed('patrol') ) && $rc_patrolled == 0;
2221
2222 # Make date header if necessary
2223 $date = $wgContLang->date( $rc_timestamp, true);
2224 $uidate = $wgLang->date( $rc_timestamp, true);
2225 $s = '';
2226 if ( $date != $this->lastdate ) {
2227 if ( '' != $this->lastdate ) { $s .= "</ul>\n"; }
2228 $s .= "<h4>{$uidate}</h4>\n<ul class=\"special\">";
2229 $this->lastdate = $date;
2230 $this->rclistOpen = true;
2231 }
2232
2233 $s .= '<li>';
2234
2235 if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2236 # Diff
2237 $s .= '(' . wfMsg( 'diff' ) . ') (';
2238 # Hist
2239 $s .= $this->makeKnownLinkObj( $rc->getMovedToTitle(), wfMsg( 'hist' ), 'action=history' ) .
2240 ') . . ';
2241
2242 # "[[x]] moved to [[y]]"
2243 $msg = ( $rc_type == RC_MOVE ) ? '1movedto2' : '1movedto2_redir';
2244 $s .= wfMsg( $msg, $this->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
2245 $this->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
2246 } elseif( $rc_namespace == NS_SPECIAL && preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
2247 # Log updates, etc
2248 $logtype = $matches[1];
2249 $logname = LogPage::logName( $logtype );
2250 $s .= '(' . $this->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
2251 } else {
2252 # Diff link
2253 if ( $rc_type == RC_NEW || $rc_type == RC_LOG ) {
2254 $diffLink = wfMsg( 'diff' );
2255 } else {
2256 if ( $unpatrolled )
2257 $rcidparam = "&rcid={$rc_id}";
2258 else
2259 $rcidparam = "";
2260 $diffLink = $this->makeKnownLinkObj( $rc->getTitle(), wfMsg( 'diff' ),
2261 "{$curIdEq}&diff={$rc_this_oldid}&oldid={$rc_last_oldid}{$rcidparam}",
2262 '', '', ' tabindex="'.$rc->counter.'"');
2263 }
2264 $s .= '('.$diffLink.') (';
2265
2266 # History link
2267 $s .= $this->makeKnownLinkObj( $rc->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' );
2268 $s .= ') . . ';
2269
2270 # M, N and ! (minor, new and unpatrolled)
2271 if ( $rc_minor ) { $s .= ' <span class="minor">'.wfMsg( "minoreditletter" ).'</span>'; }
2272 if ( $rc_type == RC_NEW ) { $s .= '<span class="newpage">'.wfMsg( "newpageletter" ).'</span>'; }
2273 if ( !$rc_patrolled ) { $s .= ' <span class="unpatrolled">!</span>'; }
2274
2275 # Article link
2276 # If it's a new article, there is no diff link, but if it hasn't been
2277 # patrolled yet, we need to give users a way to do so
2278 if ( $unpatrolled && $rc_type == RC_NEW )
2279 $articleLink = $this->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
2280 else
2281 $articleLink = $this->makeKnownLinkObj( $rc->getTitle(), '' );
2282
2283 if ( $watched ) {
2284 $articleLink = '<strong>'.$articleLink.'</strong>';
2285 }
2286 $s .= ' '.$articleLink;
2287
2288 }
2289
2290 # Timestamp
2291 $s .= '; ' . $wgLang->time( $rc_timestamp, true, $wgRCSeconds ) . ' . . ';
2292
2293 # User link (or contributions for unregistered users)
2294 if ( 0 == $rc_user ) {
2295 $userLink = $this->makeKnownLink( $wgContLang->specialPage( 'Contributions' ),
2296 $rc_user_text, 'target=' . $rc_user_text );
2297 } else {
2298 $userLink = $this->makeLink( $wgContLang->getNsText( NS_USER ) . ':'.$rc_user_text, $rc_user_text );
2299 }
2300 $s .= $userLink;
2301
2302 # User talk link
2303 $talkname=$wgContLang->getNsText(NS_TALK); # use the shorter name
2304 global $wgDisableAnonTalk;
2305 if( 0 == $rc_user && $wgDisableAnonTalk ) {
2306 $userTalkLink = '';
2307 } else {
2308 $utns=$wgContLang->getNsText(NS_USER_TALK);
2309 $userTalkLink= $this->makeLink($utns . ':'.$rc_user_text, $talkname );
2310 }
2311 # Block link
2312 $blockLink='';
2313 if ( ( 0 == $rc_user ) && $wgUser->isAllowed('block') ) {
2314 $blockLink = $this->makeKnownLink( $wgContLang->specialPage(
2315 'Blockip' ), wfMsg( 'blocklink' ), 'ip='.$rc_user_text );
2316
2317 }
2318 if($blockLink) {
2319 if($userTalkLink) $userTalkLink .= ' | ';
2320 $userTalkLink .= $blockLink;
2321 }
2322 if($userTalkLink) $s.=' ('.$userTalkLink.')';
2323
2324 # Add comment
2325 if ( '' != $rc_comment && '*' != $rc_comment && $rc_type != RC_MOVE && $rc_type != RC_MOVE_OVER_REDIRECT ) {
2326 $rc_comment=$this->formatComment($rc_comment,$rc->getTitle());
2327 $s .= $wgContLang->emphasize(' (' . $rc_comment . ')');
2328 }
2329 $s .= "</li>\n";
2330
2331 return $s;
2332 }
2333
2334 function recentChangesLineNew( &$baseRC, $watched = false ) {
2335 global $wgTitle, $wgLang, $wgContLang, $wgUser, $wgRCSeconds;
2336 global $wgUseRCPatrol, $wgOnlySysopsCanPatrol;
2337
2338 # Create a specialised object
2339 $rc = RCCacheEntry::newFromParent( $baseRC ) ;
2340
2341 # Extract fields from DB into the function scope (rc_xxxx variables)
2342 extract( $rc->mAttribs );
2343 $curIdEq = 'curid=' . $rc_cur_id;
2344
2345 # If it's a new day, add the headline and flush the cache
2346 $date = $wgContLang->date( $rc_timestamp, true);
2347 $uidate = $wgLang->date( $rc_timestamp, true);
2348 $ret = '';
2349 if ( $date != $this->lastdate ) {
2350 # Process current cache
2351 $ret = $this->recentChangesBlock () ;
2352 $this->rc_cache = array() ;
2353 $ret .= "<h4>{$uidate}</h4>\n";
2354 $this->lastdate = $date;
2355 }
2356
2357 # Should patrol-related stuff be shown?
2358 if ( $wgUseRCPatrol && $wgUser->getID() != 0 &&
2359 ( !$wgOnlySysopsCanPatrol || $wgUser->isAllowed('patrol') )) {
2360 $rc->unpatrolled = !$rc_patrolled;
2361 } else {
2362 $rc->unpatrolled = false;
2363 }
2364
2365 # Make article link
2366 if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2367 $msg = ( $rc_type == RC_MOVE ) ? "1movedto2" : "1movedto2_redir";
2368 $clink = wfMsg( $msg, $this->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
2369 $this->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
2370 } elseif( $rc_namespace == NS_SPECIAL && preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
2371 # Log updates, etc
2372 $logtype = $matches[1];
2373 $logname = LogPage::logName( $logtype );
2374 $clink = '(' . $this->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
2375 } elseif ( $rc->unpatrolled && $rc_type == RC_NEW ) {
2376 # Unpatrolled new page, give rc_id in query
2377 $clink = $this->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
2378 } else {
2379 $clink = $this->makeKnownLinkObj( $rc->getTitle(), '' ) ;
2380 }
2381
2382 $time = $wgContLang->time( $rc_timestamp, true, $wgRCSeconds );
2383 $rc->watched = $watched ;
2384 $rc->link = $clink ;
2385 $rc->timestamp = $time;
2386
2387 # Make "cur" and "diff" links
2388 if ( ( $rc_type == RC_NEW && $rc_this_oldid == 0 ) || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2389 $curLink = wfMsg( 'cur' );
2390 $diffLink = wfMsg( 'diff' );
2391 } else {
2392 $query = $curIdEq.'&diff=0&oldid='.$rc_this_oldid;
2393 $aprops = ' tabindex="'.$baseRC->counter.'"';
2394 $curLink = $this->makeKnownLinkObj( $rc->getTitle(), wfMsg( 'cur' ), $query, '' ,'' , $aprops );
2395 $diffLink = $this->makeKnownLinkObj( $rc->getTitle(), wfMsg( 'diff'), $query, '' ,'' , $aprops );
2396 }
2397
2398 # Make "last" link
2399 $titleObj = $rc->getTitle();
2400 if ( $rc->unpatrolled ) {
2401 $rcIdQuery = "&rcid={$rc_id}";
2402 } else {
2403 $rcIdQuery = '';
2404 }
2405 if ( $rc_last_oldid == 0 || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2406 $lastLink = wfMsg( 'last' );
2407 } else {
2408 $lastLink = $this->makeKnownLinkObj( $rc->getTitle(), wfMsg( 'last' ),
2409 $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
2410 }
2411
2412 # Make user link (or user contributions for unregistered users)
2413 if ( $rc_user == 0 ) {
2414 $userLink = $this->makeKnownLink( $wgContLang->specialPage( 'Contributions' ),
2415 $rc_user_text, 'target=' . $rc_user_text );
2416 } else {
2417 $userLink = $this->makeLink( $wgContLang->getNsText(
2418 Namespace::getUser() ) . ':'.$rc_user_text, $rc_user_text );
2419 }
2420
2421 $rc->userlink = $userLink;
2422 $rc->lastlink = $lastLink;
2423 $rc->curlink = $curLink;
2424 $rc->difflink = $diffLink;
2425
2426 # Make user talk link
2427 $utns=$wgContLang->getNsText(NS_USER_TALK);
2428 $talkname=$wgContLang->getNsText(NS_TALK); # use the shorter name
2429 $userTalkLink= $this->makeLink($utns . ':'.$rc_user_text, $talkname );
2430
2431 global $wgDisableAnonTalk;
2432 if ( ( 0 == $rc_user ) && $wgUser->isAllowed('block') ) {
2433 $blockLink = $this->makeKnownLink( $wgContLang->specialPage(
2434 'Blockip' ), wfMsg( 'blocklink' ), 'ip='.$rc_user_text );
2435 if( $wgDisableAnonTalk )
2436 $rc->usertalklink = ' ('.$blockLink.')';
2437 else
2438 $rc->usertalklink = ' ('.$userTalkLink.' | '.$blockLink.')';
2439 } else {
2440 if( $wgDisableAnonTalk && ($rc_user == 0) )
2441 $rc->usertalklink = '';
2442 else
2443 $rc->usertalklink = ' ('.$userTalkLink.')';
2444 }
2445
2446 # Put accumulated information into the cache, for later display
2447 # Page moves go on their own line
2448 $title = $rc->getTitle();
2449 $secureName = $title->getPrefixedDBkey();
2450 if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2451 # Use an @ character to prevent collision with page names
2452 $this->rc_cache['@@' . ($this->rcMoveIndex++)] = array($rc);
2453 } else {
2454 if ( !isset ( $this->rc_cache[$secureName] ) ) $this->rc_cache[$secureName] = array() ;
2455 array_push ( $this->rc_cache[$secureName] , $rc ) ;
2456 }
2457 return $ret;
2458 }
2459
2460 function endImageHistoryList() {
2461 $s = "</ul>\n";
2462 return $s;
2463 }
2464
2465 /**
2466 * This function is called by all recent changes variants, by the page history,
2467 * and by the user contributions list. It is responsible for formatting edit
2468 * comments. It escapes any HTML in the comment, but adds some CSS to format
2469 * auto-generated comments (from section editing) and formats [[wikilinks]].
2470 *
2471 * The &$title parameter must be a title OBJECT. It is used to generate a
2472 * direct link to the section in the autocomment.
2473 * @author Erik Moeller <moeller@scireview.de>
2474 *
2475 * Note: there's not always a title to pass to this function.
2476 * Since you can't set a default parameter for a reference, I've turned it
2477 * temporarily to a value pass. Should be adjusted further. --brion
2478 */
2479 function formatComment($comment, $title = NULL) {
2480 global $wgContLang;
2481 $comment = htmlspecialchars( $comment );
2482
2483 # The pattern for autogen comments is / * foo * /, which makes for
2484 # some nasty regex.
2485 # We look for all comments, match any text before and after the comment,
2486 # add a separator where needed and format the comment itself with CSS
2487 while (preg_match('/(.*)\/\*\s*(.*?)\s*\*\/(.*)/', $comment,$match)) {
2488 $pre=$match[1];
2489 $auto=$match[2];
2490 $post=$match[3];
2491 $link='';
2492 if($title) {
2493 $section=$auto;
2494
2495 # This is hackish but should work in most cases.
2496 $section=str_replace('[[','',$section);
2497 $section=str_replace(']]','',$section);
2498 $title->mFragment=$section;
2499 $link=$this->makeKnownLinkObj($title,wfMsg('sectionlink'));
2500 }
2501 $sep='-';
2502 $auto=$link.$auto;
2503 if($pre) { $auto = $sep.' '.$auto; }
2504 if($post) { $auto .= ' '.$sep; }
2505 $auto='<span class="autocomment">'.$auto.'</span>';
2506 $comment=$pre.$auto.$post;
2507 }
2508
2509 # format regular and media links - all other wiki formatting
2510 # is ignored
2511 $medians = $wgContLang->getNsText(Namespace::getMedia()).':';
2512 while(preg_match('/\[\[(.*?)(\|(.*?))*\]\](.*)$/',$comment,$match)) {
2513 # Handle link renaming [[foo|text]] will show link as "text"
2514 if( "" != $match[3] ) {
2515 $text = $match[3];
2516 } else {
2517 $text = $match[1];
2518 }
2519 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
2520 # Media link; trail not supported.
2521 $linkRegexp = '/\[\[(.*?)\]\]/';
2522 $thelink = $this->makeMediaLink( $submatch[1], "", $text );
2523 } else {
2524 # Other kind of link
2525 if( preg_match( wfMsgForContent( "linktrail" ), $match[4], $submatch ) ) {
2526 $trail = $submatch[1];
2527 } else {
2528 $trail = "";
2529 }
2530 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
2531 if ($match[1][0] == ':')
2532 $match[1] = substr($match[1], 1);
2533 $thelink = $this->makeLink( $match[1], $text, "", $trail );
2534 }
2535 $comment = preg_replace( $linkRegexp, $thelink, $comment, 1 );
2536 }
2537 return $comment;
2538 }
2539
2540 function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description ) {
2541 global $wgUser, $wgLang, $wgContLang, $wgTitle;
2542
2543 $datetime = $wgLang->timeanddate( $timestamp, true );
2544 $del = wfMsg( 'deleteimg' );
2545 $delall = wfMsg( 'deleteimgcompletely' );
2546 $cur = wfMsg( 'cur' );
2547
2548 if ( $iscur ) {
2549 $url = Image::wfImageUrl( $img );
2550 $rlink = $cur;
2551 if ( $wgUser->isAllowed('delete') ) {
2552 $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() .
2553 '&action=delete' );
2554 $style = $this->getInternalLinkAttributes( $link, $delall );
2555
2556 $dlink = '<a href="'.$link.'"'.$style.'>'.$delall.'</a>';
2557 } else {
2558 $dlink = $del;
2559 }
2560 } else {
2561 $url = htmlspecialchars( wfImageArchiveUrl( $img ) );
2562 if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
2563 $rlink = $this->makeKnownLink( $wgTitle->getPrefixedText(),
2564 wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
2565 urlencode( $img ) );
2566 $dlink = $this->makeKnownLink( $wgTitle->getPrefixedText(),
2567 $del, 'action=delete&oldimage=' . urlencode( $img ) );
2568 } else {
2569 # Having live active links for non-logged in users
2570 # means that bots and spiders crawling our site can
2571 # inadvertently change content. Baaaad idea.
2572 $rlink = wfMsg( 'revertimg' );
2573 $dlink = $del;
2574 }
2575 }
2576 if ( 0 == $user ) {
2577 $userlink = $usertext;
2578 } else {
2579 $userlink = $this->makeLink( $wgContLang->getNsText( Namespace::getUser() ) .
2580 ':'.$usertext, $usertext );
2581 }
2582 $nbytes = wfMsg( 'nbytes', $size );
2583 $style = $this->getInternalLinkAttributes( $url, $datetime );
2584
2585 $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a>"
2586 . " . . {$userlink} ({$nbytes})";
2587
2588 if ( '' != $description && '*' != $description ) {
2589 $sk=$wgUser->getSkin();
2590 $s .= $wgContLang->emphasize(' (' . $sk->formatComment($description,$wgTitle) . ')');
2591 }
2592 $s .= "</li>\n";
2593 return $s;
2594 }
2595
2596 function tocIndent($level) {
2597 return str_repeat( '<div class="tocindent">'."\n", $level>0 ? $level : 0 );
2598 }
2599
2600 function tocUnindent($level) {
2601 return str_repeat( "</div>\n", $level>0 ? $level : 0 );
2602 }
2603
2604 /**
2605 * parameter level defines if we are on an indentation level
2606 */
2607 function tocLine( $anchor, $tocline, $level ) {
2608 $link = '<a href="#'.$anchor.'">'.$tocline.'</a><br />';
2609 if($level) {
2610 return $link."\n";
2611 } else {
2612 return '<div class="tocline">'.$link."</div>\n";
2613 }
2614
2615 }
2616
2617 function tocTable($toc) {
2618 # note to CSS fanatics: putting this in a div does not work -- div won't auto-expand
2619 # try min-width & co when somebody gets a chance
2620 $hideline = ' <script type="text/javascript">showTocToggle("' . addslashes( wfMsg('showtoc') ) . '","' . addslashes( wfMsg('hidetoc') ) . '")</script>';
2621 return
2622 '<table border="0" id="toc"><tr id="toctitle"><td align="center">'."\n".
2623 '<b>'.wfMsgForContent('toc').'</b>' .
2624 $hideline .
2625 '</td></tr><tr id="tocinside"><td>'."\n".
2626 $toc."</td></tr></table>\n";
2627 }
2628
2629 /**
2630 * These two do not check for permissions: check $wgTitle->userCanEdit
2631 * before calling them
2632 */
2633 function editSectionScriptForOther( $title, $section, $head ) {
2634 $ttl = Title::newFromText( $title );
2635 $url = $ttl->escapeLocalURL( 'action=edit&section='.$section );
2636 return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
2637 }
2638
2639 function editSectionScript( $nt, $section, $head ) {
2640 global $wgRequest;
2641 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
2642 return $head;
2643 }
2644 $url = $nt->escapeLocalURL( 'action=edit&section='.$section );
2645 return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
2646 }
2647
2648 function editSectionLinkForOther( $title, $section ) {
2649 global $wgRequest;
2650 global $wgContLang;
2651
2652 $title = Title::newFromText($title);
2653 $editurl = '&section='.$section;
2654 $url = $this->makeKnownLink($title->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
2655
2656 if( $wgContLang->isRTL() ) {
2657 $farside = 'left';
2658 $nearside = 'right';
2659 } else {
2660 $farside = 'right';
2661 $nearside = 'left';
2662 }
2663 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
2664
2665 }
2666
2667 function editSectionLink( $nt, $section ) {
2668 global $wgRequest;
2669 global $wgContLang;
2670
2671 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
2672 # Section edit links would be out of sync on an old page.
2673 # But, if we're diffing to the current page, they'll be
2674 # correct.
2675 return '';
2676 }
2677
2678 $editurl = '&section='.$section;
2679 $url = $this->makeKnownLink($nt->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
2680
2681 if( $wgContLang->isRTL() ) {
2682 $farside = 'left';
2683 $nearside = 'right';
2684 } else {
2685 $farside = 'right';
2686 $nearside = 'left';
2687 }
2688 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
2689
2690 }
2691
2692 /**
2693 * This function is called by EditPage.php and shows a bulletin board style
2694 * toolbar for common editing functions. It can be disabled in the user
2695 * preferences.
2696 * The necessary JavaScript code can be found in style/wikibits.js.
2697 */
2698 function getEditToolbar() {
2699 global $wgStylePath, $wgLang, $wgMimeType;
2700
2701 /**
2702 * toolarray an array of arrays which each include the filename of
2703 * the button image (without path), the opening tag, the closing tag,
2704 * and optionally a sample text that is inserted between the two when no
2705 * selection is highlighted.
2706 * The tip text is shown when the user moves the mouse over the button.
2707 *
2708 * Already here are accesskeys (key), which are not used yet until someone
2709 * can figure out a way to make them work in IE. However, we should make
2710 * sure these keys are not defined on the edit page.
2711 */
2712 $toolarray=array(
2713 array( 'image'=>'button_bold.png',
2714 'open' => "\'\'\'",
2715 'close' => "\'\'\'",
2716 'sample'=> wfMsg('bold_sample'),
2717 'tip' => wfMsg('bold_tip'),
2718 'key' => 'B'
2719 ),
2720 array( 'image'=>'button_italic.png',
2721 'open' => "\'\'",
2722 'close' => "\'\'",
2723 'sample'=> wfMsg('italic_sample'),
2724 'tip' => wfMsg('italic_tip'),
2725 'key' => 'I'
2726 ),
2727 array( 'image'=>'button_link.png',
2728 'open' => '[[',
2729 'close' => ']]',
2730 'sample'=> wfMsg('link_sample'),
2731 'tip' => wfMsg('link_tip'),
2732 'key' => 'L'
2733 ),
2734 array( 'image'=>'button_extlink.png',
2735 'open' => '[',
2736 'close' => ']',
2737 'sample'=> wfMsg('extlink_sample'),
2738 'tip' => wfMsg('extlink_tip'),
2739 'key' => 'X'
2740 ),
2741 array( 'image'=>'button_headline.png',
2742 'open' => "\\n== ",
2743 'close' => " ==\\n",
2744 'sample'=> wfMsg('headline_sample'),
2745 'tip' => wfMsg('headline_tip'),
2746 'key' => 'H'
2747 ),
2748 array( 'image'=>'button_image.png',
2749 'open' => '[['.$wgLang->getNsText(NS_IMAGE).":",
2750 'close' => ']]',
2751 'sample'=> wfMsg('image_sample'),
2752 'tip' => wfMsg('image_tip'),
2753 'key' => 'D'
2754 ),
2755 array( 'image' => 'button_media.png',
2756 'open' => '[['.$wgLang->getNsText(NS_MEDIA).':',
2757 'close' => ']]',
2758 'sample'=> wfMsg('media_sample'),
2759 'tip' => wfMsg('media_tip'),
2760 'key' => 'M'
2761 ),
2762 array( 'image' => 'button_math.png',
2763 'open' => "\\<math\\>",
2764 'close' => "\\</math\\>",
2765 'sample'=> wfMsg('math_sample'),
2766 'tip' => wfMsg('math_tip'),
2767 'key' => 'C'
2768 ),
2769 array( 'image' => 'button_nowiki.png',
2770 'open' => "\\<nowiki\\>",
2771 'close' => "\\</nowiki\\>",
2772 'sample'=> wfMsg('nowiki_sample'),
2773 'tip' => wfMsg('nowiki_tip'),
2774 'key' => 'N'
2775 ),
2776 array( 'image' => 'button_sig.png',
2777 'open' => '--~~~~',
2778 'close' => '',
2779 'sample'=> '',
2780 'tip' => wfMsg('sig_tip'),
2781 'key' => 'Y'
2782 ),
2783 array( 'image' => 'button_hr.png',
2784 'open' => "\\n----\\n",
2785 'close' => '',
2786 'sample'=> '',
2787 'tip' => wfMsg('hr_tip'),
2788 'key' => 'R'
2789 )
2790 );
2791 $toolbar ="<script type='text/javascript'>\n/*<![CDATA[*/\n";
2792
2793 $toolbar.="document.writeln(\"<div id='toolbar'>\");\n";
2794 foreach($toolarray as $tool) {
2795
2796 $image=$wgStylePath.'/common/images/'.$tool['image'];
2797 $open=$tool['open'];
2798 $close=$tool['close'];
2799 $sample = addslashes( $tool['sample'] );
2800
2801 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
2802 // Older browsers show a "speedtip" type message only for ALT.
2803 // Ideally these should be different, realistically they
2804 // probably don't need to be.
2805 $tip = addslashes( $tool['tip'] );
2806
2807 #$key = $tool["key"];
2808
2809 $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
2810 }
2811
2812 $toolbar.="addInfobox('" . addslashes( wfMsg( "infobox" ) ) . "','" . addslashes(wfMsg("infobox_alert")) . "');\n";
2813 $toolbar.="document.writeln(\"</div>\");\n";
2814
2815 $toolbar.="/*]]>*/\n</script>";
2816 return $toolbar;
2817 }
2818
2819 /**
2820 * @access public
2821 */
2822 function suppressUrlExpansion() {
2823 return false;
2824 }
2825 }
2826
2827 }
2828 ?>